

var ChooseSubscriptionView = View.extend( ChooseSubscriptionView = {
   
    init: function() {
        this._super();
        this.configure();
    },
    
    configure: function() {
        var self = this;
        
        $(".subscriptions .sub-block a.btn-success").click(function(e) {
            e.preventDefault();
        
            var parent_block = $(this).parents(".sub-block")[0];
        
            $(".sub-block").each(function() {
                if( this != parent_block ) {
                    $(this).fadeOut('slow');
                }
            });
        
            $.post( $(this).attr('href'), function(data) {
                $(".registration_area").html(data).css('display', 'inline-block');
                self.bindRegistrationForm();
            });
        
            return false;
        });
    },
    
    bindRegistrationForm: function() {
        $(".registration_area .cancel").click(function() {
            $(".registration_area").hide();
            
            $(".sub-block").fadeIn('fast');
        });
        
        $(".registration_area form").submit(function(e) {
            e.preventDefault();
            
            var url = $(this).attr("action");
            var query = $(this).serialize();
            
            $.ajax({
                url: url,
                data: query,
                type: 'post',
                dataType: 'json',
                success: function(data) {
                    console.log(data);
                },
                error: function(xhr) {
                    console.log(xhr.responseText);
                }
            });
        });
    }
});

$(document).ready( function() {
    var view =  new ChooseSubscriptionView();
    App.getController().setView(view);
});
